/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import type { ProColumns } from '@ant-design/pro-table';
import type { StringObjType } from '../../AmountApply/index.d';
import { electronicInvoice } from './hooks';

export const getColumns = (_source: string) => {
  const wkdReceiptColumns: ProColumns<StringObjType>[] = [
    {
      title: '申请日期',
      dataIndex: 'create_at',
      width: 170,
      align: 'center',
      search: false,
    },
    {
      title: '开票来源',
      dataIndex: 'source',
      hideInTable: _source === 'jdk',
      width: 150,
      align: 'center',
      search: false,
      render: (_, record) => {
        const platform = {
          wkd: '微快递',
          jdk: '聚单客',
          regiment: '全寄',
        };
        const { source } = record;
        return platform[source];
      },
    },
    {
      title: '发票类型',
      dataIndex: 'id_card_number',
      width: 150,
      align: 'center',
      search: false,
      renderText: () => '电子发票',
    },
    {
      title: '申请人手机号',
      dataIndex: 'mobile',
      width: 160,
      align: 'center',
      search: false,
    },
    {
      title: '抬头类型',
      dataIndex: 'type',
      width: 100,
      align: 'center',
      search: false,
      renderText: (_, record) => (record.type == 'company' ? '企业' : '个人'),
    },
    {
      title: '关联发票抬头',
      dataIndex: 'title',
      width: 160,
      align: 'center',
      search: false,
    },
    {
      title: '关联开票税号',
      dataIndex: 'tax_number',
      width: 160,
      align: 'center',
      search: false,
      renderText: (_, record) => (record.type == 'company' ? record.tax_number : ''),
    },
    {
      title: '公司地址',
      dataIndex: 'company_address',
      width: 160,
      align: 'center',
      search: false,
    },
    {
      title: '公司电话',
      dataIndex: 'company_tel',
      width: 160,
      align: 'center',
      search: false,
    },
    {
      title: '开户银行',
      dataIndex: 'bank_name',
      width: 160,
      align: 'center',
      search: false,
    },
    {
      title: '银行账户',
      dataIndex: 'bank_account',
      width: 160,
      align: 'center',
      search: false,
    },
    {
      title: '备注',
      dataIndex: 'remark',
      width: 160,
      align: 'center',
      search: false,
    },
    {
      title: '邮箱',
      dataIndex: 'email',
      width: 160,
      align: 'center',
      search: false,
    },
    {
      title: '开票金额',
      dataIndex: 'total_price',
      width: 160,
      align: 'center',
      search: false,
    },
    {
      title: '发票号',
      dataIndex: 'ticket_sn',
      width: 160,
      align: 'center',
      search: false,
      render: (text) => (text != '0' ? text : ''),
    },
  ];
  return wkdReceiptColumns;
};

export const stationReceiptColumns: ProColumns<StringObjType>[] = [
  {
    title: '申请日期',
    dataIndex: 'created_at',
    align: 'center',
    search: false,
    width: '5%',
  },
  {
    title: '申请网点编号',
    dataIndex: 'index_shop_id',
    align: 'center',
    search: false,
    width: '10%',
  },
  {
    title: '发票类型',
    dataIndex: 'invoice_type',
    align: 'center',
    search: false,
    width: '5%',
    renderText: (text) => (text == 1 ? '普通发票' : '专用发票'),
  },
  {
    title: '申请网点',
    dataIndex: 'index_shop_name',
    align: 'center',
    search: false,
    width: '10%',
  },
  {
    title: '关联开票信息（抬头）',
    dataIndex: 'invoice_title',
    align: 'center',
    search: false,
    width: '15%',
  },
  {
    title: '邮箱',
    dataIndex: 'email',
    align: 'center',
    search: false,
    width: '10%',
  },
  {
    title: '开票金额',
    dataIndex: 'total_money',
    align: 'center',
    search: false,
    width: '5%',
  },
  {
    title: '联系电话',
    dataIndex: 'receiver_tel',
    align: 'center',
    search: false,
    width: '10%',
  },
  {
    title: '高灯开票结果',
    dataIndex: 'state',
    align: 'center',
    search: false,
    width: '10%',
    renderText: (text) => {
      if (text < 1) {
        return '未开票';
      }
      if (text == 1) {
        return '已提交';
      }
      if (text == 2) {
        return '开票成功';
      }
      return '';
    },
  },
  {
    title: '结果详情',
    dataIndex: 'message',
    align: 'center',
    search: false,
    width: '10%',
  },
  {
    title: '发票号',
    dataIndex: 'ticket_sn',
    align: 'center',
    search: false,
    width: '10%',
  },
  electronicInvoice({ title: '电子发票', dataIndex: 'pdf_url', fixed: 'right', width: 80 }),
];
